package com.dragon.mmochat.model.battle.record;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.MmochatSerial;
import com.dragon.mmochat.model.enumType.MmochatBattleType;

//战斗录像,战场基本信息
public class MmochatBattleRecord implements Comparable<MmochatBattleRecord> {
	private static MmochatSerial serial = new MmochatSerial();

	private MmochatBattleType type = null;// 录像类型
	private String name1;// 一方的名字
	private String name2;// 另一方的名字
	private boolean save = false;// 是否保存此录像
	private long lastShowTime = System.currentTimeMillis();// 最近一次查看此录像的时间

	private long startTick = System.currentTimeMillis();// 整个战斗开始时间点
	private int id;// 录像ID是负数
	private int turn = 1;

	// 左队+右队成员
	Map<Byte, MmochatRoleRecord> roles = new ConcurrentHashMap<Byte, MmochatRoleRecord>();

	// 战斗每回合数据
	List<MmochatBattleRoundRecord> rounds = new ArrayList<MmochatBattleRoundRecord>();

	// 战斗聊天
	List<MmochatBattleChatRecord> chats = new ArrayList<MmochatBattleChatRecord>();

	// 闹钟消失记录
	List<MmochatBattleActionClockRecord> clocks = new ArrayList<MmochatBattleActionClockRecord>();

	public MmochatBattleType getType() {
		return type;
	}

	public void setType(MmochatBattleType type) {
		this.type = type;
	}

	public String getName1() {
		return name1;
	}

	public void setName1(String name1) {
		this.name1 = name1;
	}

	public String getName2() {
		return name2;
	}

	public void setName2(String name2) {
		this.name2 = name2;
	}

	public long getStartTick() {
		return startTick;
	}

	public void setStartTick(long startTick) {
		this.startTick = startTick;
	}

	public MmochatBattleRecord() {
		this.id = -1 * serial.addAndGetSerialId();
	}

	public static MmochatSerial getSerial() {
		return serial;
	}

	public static void setSerial(MmochatSerial serial) {
		MmochatBattleRecord.serial = serial;
	}

	public int getId() {
		return id;
	}

	public void setId(int battleId) {
		this.id = battleId;
	}

	public int getTurn() {
		return turn;
	}

	public void setTurn(int turn) {
		this.turn = turn;
	}

	public Map<Byte, MmochatRoleRecord> getRoles() {
		return roles;
	}

	public void setRoles(Map<Byte, MmochatRoleRecord> roles) {
		this.roles = roles;
	}

	public List<MmochatBattleRoundRecord> getRounds() {
		return rounds;
	}

	public void setRounds(List<MmochatBattleRoundRecord> rounds) {
		this.rounds = rounds;
	}

	public List<MmochatBattleChatRecord> getChats() {
		return chats;
	}

	public void setChats(List<MmochatBattleChatRecord> chats) {
		this.chats = chats;
	}

	public List<MmochatBattleActionClockRecord> getClocks() {
		return clocks;
	}

	public void setClocks(List<MmochatBattleActionClockRecord> clocks) {
		this.clocks = clocks;
	}

	public boolean isSave() {
		if (type != null) {
			switch (type) {
			case 武道会比赛:
			case 个人争霸赛:
			case 天下第一争霸赛:
			case 跨服武道会比赛: {
				// 各大比赛固定为保存录像
				return true;
			}
			default:
				break;
			}
		}
		return save;
	}

	public boolean isAlive() {
		if (type != null) {
			switch (type) {
			case 武道会比赛:
			case 个人争霸赛:
			case 天下第一争霸赛:
			case 跨服武道会比赛: {
				// 各大比赛固定为保存录像
				return true;
			}
			default:
				break;
			}
		}
		return System.currentTimeMillis() - lastShowTime < MmochatConstant.recordLifeTime
				* MmochatConstant.MS_PER_MINUTE;
	}

	public void setSave(boolean save) {
		this.save = save;
	}

	public long getLastShowTime() {
		return lastShowTime;
	}

	public void setLastShowTime(long lastShowTime) {
		this.lastShowTime = lastShowTime;
	}

	@Override
	public int compareTo(MmochatBattleRecord arg0) {
		return (int) (arg0.getStartTick() - startTick);
	}

}
